import { createElement } from "../createElement";
import type { TextDomType, ElementAttrsType } from "../types";

/**
 * 创建一个显示text的标签
 * @param tagsName 创建的原生tag类型
 * @param elementAttrs 标签的属性
 * @returns 创建好的dom对象
 */
export function initTextDom(tagsName: keyof HTMLElementTagNameMap, elementAttrs: ElementAttrsType): HTMLElement & TextDomType {
    const fourmulaEle = createElement(tagsName, elementAttrs);
    let appenFns: TextDomType = {
        isMounted(): boolean {
            return Boolean(fourmulaEle.parentElement);
        },
        updateText(text: string | number) {
            if (!this.isMounted()) return;
            fourmulaEle.innerText = String(text);
        },
    }
    return Object.assign(fourmulaEle, appenFns)
}